/**
 * 组件配置库
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/6/12
 */

const form = [
    { type: 'input', label: '单行文本', icon: 'icon-danhangwenben' },
    { type: 'textarea', label: '多行文本', icon: 'icon-duohangwenben' },
    { type: 'number', label: '数字输入', icon: 'icon-jishuqi' },
    { type: 'radio', label: '单选项', icon: 'icon-danxuan' },
    { type: 'select', label: '下拉选择', icon: 'icon-m-xialakuang' },
    { type: 'checkbox', label: '多选项', icon: 'icon-duoxuankuang1' },
    { type: 'cascader', label: '级联选择', icon: 'icon-dagang_jilianxuanzeqi' },
    { type: 'time', label: '时间选择', icon: 'icon-shijian' },
    { type: 'date', label: '日期选择', icon: 'icon-riqi' },
    { type: 'switches', label: '开关', icon: 'icon-kaiguan-guan' },
    { type: 'slider', label: '滑块', icon: 'icon-slider' },
    { type: 'rate', label: '评分', icon: 'icon-pingfen1' },
    { type: 'color', label: '颜色选择', icon: 'icon-yanse' },
    { type: 'upload', label: '上传', icon: 'icon-shangchuan' },
    { type: 'rich_text', label: '富文本', icon: 'icon-fuwenben' },
    // { type: 'tree', label: '树形控件', icon: 'icon-shuxing' },
    // { type: 'icon', label: 'ICON', icon: 'icon-icon' },
    // { type: 'transfer', label: '穿梭框', icon: 'icon-m-chuansuokuang' },
]

const aux = [
    { type: 'hint', label: '提示', icon: 'icon-tishi2' },
    // { type: 'button', label: '按钮', icon: 'icon-anniu' },
    { type: 'html', label: '文字', icon: 'icon-wenben' },
]
const layout = [
    // TODO 嵌套布局目前有点问题需要后续处理
    // { type: 'layout', label: '布局', icon: 'icon-buju' },
    // { type: 'space', label: '间隔', icon: 'icon-jiange' },
    { type: 'divider', label: '分割线', icon: 'icon-fengexian' },
]
export const library = [
    { title: '基础组件', item: form },
    { title: '辅助组件', item: aux },
    { title: '布局组件', item: layout },
]

// 获取主键标签标题
export const getLibraryName = (type: string) => {
    for (const item of form) {
        if (item.type === type) {
            return item.label
        }
    }
    return ''
}

// 组件表单规则
export const getFormComponentRules = (type: string) => {
    return formComponentRules[type] || formComponentRules['input']
}

const options = [
    { label: '否', value: 0 },
    { label: '是', value: 1 },
]

const default_rule = [
    { type: 'divider', label: '表单设置' },
    { label: '字段标题', required: true, value: '单行文本', field: 'title' },
    { label: '字段名称', required: true, field: 'field' },
    { label: '默认值', field: 'default_val' },
    { label: '暂位符', field: 'placeholder' },
    { label: '是否必填', field: 'is_required', type: 'radio', options, value: 0 },
    { label: '是否列表', field: 'is_table', type: 'radio', options, value: 0 },
    { label: '是否搜索', field: 'is_search', type: 'radio', options, value: 0 },
    { label: '是否投稿', field: 'is_release', type: 'radio', options, value: 0 },
    { label: '提示信息', field: 'tips', type: 'textarea' },
    { label: '备注信息', field: 'intro', type: 'textarea' },
]

// 表单组件规则信息
const formComponentRules: { [key: string]: any[] } = {
    input: [...default_rule],
    layout: [],
}
